var BetList = (function($) {
	/*
	 * Full model, used for copying var colNames = [ 'User Id', 'Bet type',
	 * 'Date', 'Choice', 'Channel', 'Odds', 'Stake', 'Win/Lose', 'Comm', 'Agent
	 * WL', 'Affiliate WL', 'Affiliate Comm', 'Status' ]; var colModel =
	 * [userIdModel,transTypeModel,transDateModel,choideModel,channelNameModel,oddsModel,stakeModel,
	 * winLoseModel,commissionModel,agentWlModel,affiliateWlModel,affiliateCommModel.statusModel];
	 * 
	 */

	var userIdModel = {
		name : 'user_id',
		index : 'user_id',
		width : 60,
		sorttype : "int",
		hidden : true
	};
	var userNameModel = {
		name : 'username',
		index : 'username',
		width : 60,
		sorttype : "string"
	};
	var transTypeModel = {
		name : 'trans_type',
		index : 'trans_type',
		width : 90,
		sorttype : "string"
	};
	var transDateModel = {
		name : 'trans_date',
		index : 'trans_date',
		width : 100,
		sorttype : "string"
	};
	var choideModel = {
		name : 'choice',
		index : 'choice',
		width : 80,
		align : "right",
		sorttype : "string"
	};
	var channelNameModel = {
		name : 'channel_name',
		index : 'channel_name',
		width : 80,
		align : "right",
		sorttype : "int"
	};
	var oddsModel = {
		name : 'odds',
		index : 'odds',
		width : 80,
		align : "right",
		sorttype : "float",
		formatter : 'currency'
	};
	var stakeModel = {
		name : 'stake',
		index : 'stake',
		width : 80,
		align : "right",
		sorttype : "float",
		formatter : 'currency'
	};
	var winLoseModel = {
		name : 'win_lose',
		index : 'win_lose',
		width : 80,
		align : "right",
		sorttype : "float",
		formatter : 'currency'
	};
	var commissionModel = {
		name : 'commission',
		index : 'commission',
		width : 80,
		align : "right",
		sorttype : "float",
		formatter : 'currency'
	};
	var agentWlModel = {
		name : 'agent_win_lose',
		index : 'agent_win_lose',
		width : 80,
		align : "right",
		sorttype : "float",
		formatter : 'currency'
	};
	var affiliateWlModel = {
		name : 'affiliate_win_lose',
		index : 'affiliate_win_lose',
		width : 80,
		align : "right",
		sorttype : "float",
		formatter : 'currency'
	};
	var affiliateCommModel = {
		name : 'affiliate_commission',
		index : 'affiliate_commission',
		width : 80,
		align : "right",
		sorttype : "float",
		formatter : 'currency'
	};
	var statusModel = {
		name : 'status',
		index : 'status',
		width : 80,
		align : "center",
		sorttype : "string",
		formatter : 'string'
	};

	return {
		initTotalBetsEvent : function() {
			$("#submit").click(function() {
				BetList.bindTotalBets();
				return false;
			});
		},
		initTotalBets : function() {
			BetList.initTotalBetsEvent();
			BetList.bindTotalBets();
		},
		initBetList : function() {
			BetList.bindBetList();
		},
		initStatement : function() {
			Report.initDateRangePicker();
			$("#submit").click(function(){
				BetList.bindStatement();
			});
		},
		bindTotalBets : function() {

			var gridOption = $.extend(Report.gridOption, {
				height : 500,
				colNames : [ 'UserId', 'User', 'Bet type', 'Date', 'Choice',
						'Channel', 'Odds', 'Stake' ],
				colModel : [ userIdModel, userNameModel, transTypeModel,
						transDateModel, choideModel, channelNameModel, oddsModel,
						stakeModel ]
			});

			$.blockUI();
			$.ajax( {
				type : "POST",
				url : "index.php/admin/report/totalbetsData",
				dataType : "json",
				data : {
					channel_id : $("#channel_id").val(),
					trans_type : $("#trans_type").val()
				},
				success : function(response) {
					// Show the grid
					gridOption.data = response.Main;
					gridOption.userData = response.Total;

					$("#jqgrid-table").jqGrid('GridUnload');
					$("#jqgrid-table").jqGrid(gridOption);
					Report.initColumnChooser();

				},
				complete : function() {
					$.unblockUI()
				}
			});
		},
		bindBetList : function() {

			var colNames = [ 'User Id', 'User', 'TransType', 'Date', 'Choice',
					'Channel', 'Odds', 'Stake', 'Win/Lose', 'Comm', 'Agent WL',
					'Affiliate WL', 'Affiliate Comm', 'Status' ];
			var colModel = [ userIdModel, userNameModel, transTypeModel, transDateModel,
					choideModel, channelNameModel, oddsModel, stakeModel,
					winLoseModel, commissionModel, agentWlModel,
					affiliateWlModel, affiliateCommModel,statusModel ];
			var gridOption = $.extend(Report.gridOption, {
				height : 500,
				colNames : colNames,
				colModel : colModel
			});

			$.blockUI();
			$.ajax( {
				type : "POST",
				url : "index.php/admin/report/betlistData",
				dataType : "json",
				data : {
					fromdate : $("#fromdate").val(),
					todate : $("#todate").val(),
					user_id : $("#user_id").val(),
				},
				success : function(response) {
					// Show the grid
					gridOption.data = response.Main;
					gridOption.userData = response.Total;

					$("#jqgrid-table").jqGrid('GridUnload');
					$("#jqgrid-table").jqGrid(gridOption);
					Report.initColumnChooser();

				},
				complete : function() {
					$.unblockUI()
				}
			});
		},
		bindStatement : function() {

			var colNames = [ 'User Id', 'User', 'TransType', 'Date', 'Choice',
					'Channel', 'Odds', 'Stake', 'Win/Lose', 'Comm', 'Agent WL',
					'Affiliate WL', 'Affiliate Comm', 'Status' ];
			var colModel = [ userIdModel, userNameModel, transTypeModel, transDateModel,
					choideModel, channelNameModel, oddsModel, stakeModel,
					winLoseModel, commissionModel, agentWlModel,
					affiliateWlModel, affiliateCommModel,statusModel ];
			var gridOption = $.extend(Report.gridOption, {
				height : 500,
				colNames : colNames,
				colModel : colModel
			});

			$.blockUI();
			$.ajax( {
				type : "POST",
				url : "index.php/admin/report/statementData",
				dataType : "json",
				data : {
					fromdate : $("#fromdate").val(),
					todate : $("#todate").val(),
					username : $("#username").val(),
					trans_type:$("#trans_type").val()
				},
				success : function(response) {
					// Show the grid
					gridOption.data = response.Main;
					gridOption.userData = response.Total;

					$("#jqgrid-table").jqGrid('GridUnload');
					$("#jqgrid-table").jqGrid(gridOption);
					Report.initColumnChooser();

				},
				complete : function() {
					$.unblockUI()
				}
			});
		}
	};
})(jQuery);
